//
//  TrackDatabase.h
//  MantuPlay
//
//  Created by Markus Sintonen on 22.3.2009.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <string>
#import "FMDatabase.h"
#import "SynthesizeSingleton.h"

@interface TrackDatabase : NSObject {
@private
	FMDatabase *db;
}

SINGLETON_INTERFACE(TrackDatabase, sharedTrackDatabase)

-(NSArray*)tracksFromAlbum:(NSString*)album artist:(NSString*)artist genre:(NSString*)genre orderByTrackNumber:(BOOL)orderByTrackNum;
-(NSArray*)albumsFromArtist:(NSString*)artist genre:(NSString*)genre;
-(NSArray*)artistsFromGenre:(NSString*)genre;
-(NSArray*)allGenres;

-(NSString*)getFilepathForFirstTrackInAlbum:(NSString*)album;

-(void)clearDatabaseCachedStatements;
@end

//Private methods
@interface TrackDatabase ()
-(void)scanTracksFromDirectory:(std::string)directory relativeToTrackScanningDirectoryID:(unsigned int)scanDirectoryID;
-(void)setupTrackDatabase;

-(NSArray*)databaseObjectArrayWithClasses:(Class)dbClass fromResultSet:(FMResultSet*)rs;

-(NSString*)constructFilterSqlQueryWithAlbum:(NSString*)album artist:(NSString*)artist genre:(NSString*)genre;
-(NSArray*)constructSqlQueryArgumentsWithAlbum:(NSString*)album artist:(NSString*)artist genre:(NSString*)genre;

BOOL isMP3FileExtension(const char *filename);
@end

@interface AlbumArtLoadOperation : NSOperation {
	id imageView;
	NSString *album;
	CGSize size;
}
-(id)initWithImageView:(id)imView albumName:(NSString*)albumName imageSize:(CGSize)imageSize;
@end
